<template>
	<view>
		<view class="sub_acc">
			<view class="suboverall">
				<view class="subintroduce">
					你好，XXX
				</view>
				<view class="submessage">
					信息已为您加密处理，请放心使用
				</view>
			</view>
		</view>


		<view class="subname">
			<view class="uni-form-item uni-column" style="display: flex;border-bottom: 1px solid #eee;">
				<!-- <view style="flex: 1;line-height: 42px;">姓名</view> -->
				<input style="padding: 15px 0 15px 0;" class="uni-input" value="姓名" disabled="true" />
				<view style="flex: 5;text-align: right;">
					<input style="padding: 15px;color: gray" class="uni-input" v-model="username"
						placeholder="请输入子账号持有人真实姓名" />
				</view>
			</view>
			
			<view class="uni-form-item uni-column" style="display: flex;border-bottom: 1px solid #eee;">
				<!-- <view style="flex: 1;line-height: 42px;">姓名</view> -->
				<input style="padding: 15px 0 15px 0;" class="uni-input" value="账号" disabled="true"/>
				<view style="flex: 5;text-align: right;">
					<input style="padding: 15px;color: gray" class="uni-input" v-model="mobile_number"
						placeholder="请输入手机作为账号" />
				</view>
			</view>
			
			<view class="uni-form-item uni-column" style="display: flex;border-bottom: 1px solid #eee;">
				<!-- <view style="flex: 1;line-height: 42px;">姓名</view> -->
				<input style="padding: 15px 0 15px 0;" class="uni-input" value="密码" disabled="true"/>
				<view style="flex: 5;text-align: right;">
					<input type="password" style="padding: 15px;color: gray" class="uni-input" v-model="password"
						placeholder="请输入密码" />
				</view>
			</view>
			<view class="uni-form-item uni-column" style="display: flex;border-bottom: 1px solid #eee;">
				<!-- <view style="flex: 1;line-height: 42px;">姓名</view> -->
				<input style="padding: 15px 0 15px 0;" class="uni-input" value="确认密码" disabled="true"/>
				<view style="flex: 5;text-align: right;">
					<input type="password" style="padding: 15px;color: gray" class="uni-input" v-model="password2"
						placeholder="请再次输入密码" />
				</view>
			</view>
			<!-- <view class="uni-form-item uni-column" style="display: flex;border-bottom: 1px solid #eee;">
				<input style="padding: 15px 0 15px 0;" class="uni-input" value="手机号" disabled="true" />
				<view style="text-align: right;">
					<input type="number" style="padding: 15px;color: gray" class="uni-input" v-model="mobile_number"
						placeholder="请输入银行卡预留手机号" />
				</view>
			</view> -->
			<view class="uni-form-item uni-column" style="display: flex;border-bottom: 1px solid #eee;">
				<view style="flex: 2;line-height: 42px;"><input style="padding: 15px 0 15px 0;" class="uni-input" value="验证码" disabled="true" /></view>
				<view style="flex: 6;text-align: right;">
					<input type="number" style="padding: 15px;color: gray" class="uni-input" v-model="code"
						placeholder="请输入验证码" />
				</view>
				<view style="flex: 3;text-align: right;">
					<button style="padding: 5px 10px;margin-top: 5px;margin-right: 10px;" @click="sendCode" size="mini">发送短信</button>
				</view>
			</view>
		</view>


		<view class="uni-form-item uni-column" style="margin: 20px;">
			<checkbox-group @change="read">
				<label style="font-size: 14px;color: gray;">
					<checkbox style="transform:scale(0.7)" value="1" :checked=is_read />我已阅读<view style="display: inline-block;">《用户协议》</view>
				</label>
			</checkbox-group>
		</view>
		
		<button type="primary" style="margin: 20px; padding: 5px 0; font-size: 12px;" @click="bind()">
			立即绑定
		</button>

		<view class="subdetails">
			为了保障账号安全，请妥善开通子账号并保存
		</view>

		<view class="subservice">
			<image src="../../static/service.png" style="width: 15px; height: 15px; margin: 15px 5px 0 0;">
		
			</image>
				我的客服
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				username: '',
				mobile_number: '',
				password: '',
				password2: '',
				code: '',
				is_read: false,
			}
		},
		onLoad() {
			
		},
		methods: {
			read(e) {
				this.is_read = !this.is_read;
			},
			sendCode() {
				if (this.mobile_number == '') {
					return;
				}
				this.$api.postSendCode({
					mobile_number: this.mobile_number,
				}).then(res => {
					if (res.meta.code == '000') {
						uni.showToast({
							title: res.data.meta.msg,
							duration: 2000,
							icon: 'none',
						})
					}
				})
			},
			bind() {
				if (!this.is_read) {
					uni.showToast({
						title: '请确定已阅读协议',
						duration: 2000,
						icon: 'none',
					})
					return;
				}
				if (this.mobile_number == ''
				|| this.username == ''
				|| this.password == ''
				|| this.code == ''
				) {
					return;
				}
				if (this.password != this.password2) {
					uni.showToast({
						title: '两次密码不一致',
						duration: 2000,
						icon: 'none',
					})
					return;
				}
				let uid = uni.getStorageSync('uid');
				this.$api.postBindSub({
					username: this.username,
					mobile_number: this.mobile_number,
					password: this.password,
					code: this.code,
					uid: uid,
				}).then(res => {
					if (res.meta.code == '000') {
						uni.navigateBack();
					}
				})
			},
		}
	}
</script>

<style>
	.sub_acc {
		background-color: #F1F1F1;
		padding: 10px 0;
	}

	.suboverall {
		margin-left: 15px;
		/* font-weight: lighter; */
	}

	.subintroduce {
		font-size: 18px;
		margin-bottom: 8px;
		font-weight: bold;
	}

	.submessage {
		font-size: 12px;
		color: #606266;
		margin-bottom: 10px;
		font-weight: bold;
	}

	.binding {
		background: #007AFF;
		text-align: center;
		margin: 20px 15px 10px 15px;
		padding: 12px;
		border-radius: 5px;
		font-size: 12px;
		color: #FFFFFF;
	}
	.subname{
		margin-left: 15px;
		font-size: 15px;
		white-space: nowrap
	}
	.subfind{
		padding: 20px 10px 10px 0;
		border-bottom: 1px solid #F1F1F1;
		
	}
	.subexplain{
		padding-left: 30px;
		text-align: right;
		
	}
	.subadd{
		font-size: 11px;
		color: #808080;
		padding-left: 15px;
	}
	.subdetails{
		text-align: center;
		font-size: 11px;
		color: #555555;
	}
	.subservice{
		text-align: center;
		font-size: 11px;
		color: #808080;
		margin: 50px 0;
		text-decoration: underline;
	}
	
</style>
